//
//  AMBaseResponseEntity.m
//  WeiDu_1_0
//
//  Created by foguo-mac-1 on 01/07/16.
//  Copyright (c) 2016 WeiDu Energy Tech. All rights reserved.
//

#import "HOBaseResponseEntity.h"
#import "Logger.h"
#import "HOConstants.h"

@implementation HOAPIError



@end

@implementation HOBaseResponseEntity

static NSMutableDictionary *errorDic;

- (id)initWithRequest:(HOBaseRequestEntity *)request
{
    if(self = [super init])
    {
        self.arrayData = [[[NSMutableArray alloc]init] autorelease];
        self.dicData = [[[NSMutableDictionary alloc]init] autorelease];
        self.baseRequest = request;
        self.action = request.action;
		self.apiError = [[[HOAPIError alloc] init] autorelease];
        if(errorDic == nil)
        {
            LogInf(@"errorDic:%@", errorDic);
            errorDic = [[NSMutableDictionary alloc]init];
			[errorDic setObject:[self getError:NSLocalizedString(@"" , @"" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_NON]];
			
			[errorDic setObject:[self getError:NSLocalizedString(@"检测到网络已断开, 请设置您的网络!", @"检测到网络已断开, 请设置您的网络!" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_NETWORK_DOWN]];
			[errorDic setObject:[self getError:NSLocalizedString(@"服务器异常，请稍后再连接!", @"服务器异常，请稍后再连接!" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_SERVER_DOWN]];
//			[errorDic setObject:[self getError:NSLocalizedString(@"网络不给力, 点击刷新", @"网络不给力, 点击刷新") withOperate: OPERATION_REQUEST_AGAIN]
//						 forKey:[NSNumber numberWithInt:ERROR_CODE_NETWORK_DOWN]];
			
            [errorDic setObject:[self getError:NSLocalizedString(@"请求数据为空, 请联系管理员!", @"请求数据为空, 请联系管理员!" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_RESPONSEDATA_EMPTY]];
            [errorDic setObject:[self getError:NSLocalizedString(@"请求数据无效, 请联系管理员!", @"请求数据无效, 请联系管理员!" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_RESPONSEDATA_INVALIDE]];
            [errorDic setObject:[self getError:NSLocalizedString(@"解析数据出错, 请联系管理员!", @"解析数据出错, 请联系管理员!" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_JSONPARSE_FAILED]];
            
            [errorDic setObject:[self getError:NSLocalizedString(@"请求详细数据为空, 请联系管理员!", @"请求详细数据为空, 请联系管理员!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_JSON_DATANODE_EMPTY]];
            [errorDic setObject:[self getError:NSLocalizedString(@"请求详细数据无效, 请联系管理员!", @"请求详细数据无效, 请联系管理员!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_JSON_DATANODE_INVALIDE]];
			[errorDic setObject:[self getError:NSLocalizedString(@"解析详细数据出错, 请联系管理员!", @"解析详细数据出错, 请联系管理员!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_JSON_DATANODE_PARSE_FAILED]];
			[errorDic setObject:[self getError:NSLocalizedString(@"请求未知错误, 请联系管理员!", @"请求未知错误, 请联系管理员!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10005]];
			
			
			[errorDic setObject:[self getError:NSLocalizedString(@"系统出错,请联系管理员！", @"系统出错,请联系管理员！" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10001]];//系统错误
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您的登录信息已经失效，请重新登陆！", @"您的登录信息已经失效，请重新登陆！" ) withOperate: OPERATION_LOGIN_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10002]];//用户TOKEN检验失败或则已过期
			
			[errorDic setObject:[self getError:NSLocalizedString(@"请求数据出错,请联系管理员！", @"请求数据出错,请联系管理员！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10004]];//:MaxId(用于列表分页)不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"系统出错,请联系管理员！", @"系统出错,请联系管理员！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10005]];//未知错误
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您的登录信息有误，请重新登陆！", @"您的登录信息有误，请重新登陆！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10022]];//DevID不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您的登录信息有误，请重新登陆！", @"您的登录信息有误，请重新登陆！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10023]];//RegistrationID不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您的账号未注册，请注册后登陆！", @"您的账号未注册，请注册后登陆！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10024]];//未授权登录帐号
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您的账户不存在，请重新填写正确账户后登陆！", @"您的账户不存在，请重新输入正确账户后登陆！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10025]];//用户不存在或被禁用
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您输入的账户信息无效，请重新输入！", @"您输入的账户信息无效，请重新输入！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10026]];//用户手机号不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您输入的手机号格式有误，请重新注册！", @"您输入的手机号格式有误，请重新注册！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10027]];//手机号格式错误
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您输入的手机号已被注册，请重新注册！", @"您输入的手机号已被注册，请重新注册！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10028]];//手机号被占用
			
			[errorDic setObject:[self getError:NSLocalizedString(@"用户名长度必须在6-30个字符以内，请重新填写！", @"用户名长度必须在6-30个字符以内，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10029]];//用户名长度必须在6-30个字符以内
			
			[errorDic setObject:[self getError:NSLocalizedString(@"用户名已被注册，请重新填写！", @"用户名已被注册，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10030]];//用户名被占用
			
			[errorDic setObject:[self getError:NSLocalizedString(@"密码长度必须在6-30个字符之间，请重新填写！", @"密码长度必须在6-30个字符之间，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10031]];//密码长度必须在6-30个字符之间
			
			[errorDic setObject:[self getError:NSLocalizedString(@"邮箱格式不正确，请重新填写！", @"邮箱格式不正确，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10032]];//邮箱格式不正确
			
			[errorDic setObject:[self getError:NSLocalizedString(@"邮箱长度必须在1-32个字符之间，请重新填写！", @"邮箱长度必须在1-32个字符之间，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10033]];//邮箱长度必须在1-32个字符之间
			
			[errorDic setObject:[self getError:NSLocalizedString(@"邮箱被禁止注册，请重新填写！", @"邮箱被禁止注册，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10034]];//邮箱被禁止注册
			
			[errorDic setObject:[self getError:NSLocalizedString(@"邮箱被占用，请重新填写！", @"邮箱被占用，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10035]];//邮箱被占用
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您输入的手机格式不正确，请重新填写！", @"您输入的手机格式不正确，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10036]];//手机格式不正确
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您输入的手机被禁止注册，请重新填写！", @"您输入的手机被禁止注册，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10037]];//手机被禁止注册
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您输入的手机号已被注册，请重新注册！", @"您输入的手机号已被注册，请重新注册！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10038]];//手机号被占用
			
			[errorDic setObject:[self getError:NSLocalizedString(@"原始密码不能为空，请重新填写！", @"原始密码不能为空，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10039]];//原始密码不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"新密码不能为空，请重新填写！", @"新密码不能为空，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10040]];//新密码不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"密码不能为空，请重新填写！", @"密码不能为空，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10041]];//确认密码不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"两次密码输入不一致，请重新填写！", @"两次密码输入不一致，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10042]];//两次密码输入不一致
			
			[errorDic setObject:[self getError:NSLocalizedString(@"密码错误，请重新填写！", @"密码错误，请重新填写！" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10043]];//密码错误
			
			
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您选择的故障分类未找到，请重新请求!", @"您选择的故障分类未找到，请重新请求!" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10200]];//故障分类ID不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您选择的部门未找到，请重新请求!", @"您选择的部门未找到，请重新请求!" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10201]];//部门ID不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"故障详情不能为空,请重新填写!", @"故障详情不能为空,请重新填写!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10202]];//故障详情不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您选择的故障分类不存在，请重新选择!", @"您选择的故障分类不存在，请重新选择!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10203]];//故障分类不存在
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您选择的部门不存在，请重新选择!", @"您选择的部门不存在，请重新选择!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10204]];//部门不存在
			
			[errorDic setObject:[self getError:NSLocalizedString(@"报修失败，请重新报修!", @"报修失败，请重新报修!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10205]];//报修失败:
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您选择的处理人不存在，请重新选择!", @"您选择的处理人不存在，请重新选择!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10206]];//处理人不存在
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您选择的报修区域不存在，请重新选择!", @"您选择的报修区域不存在，请重新选择!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10207]];//报修区域不存在
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您选择的区域楼宇不存在，请重新选择!", @"您选择的区域楼宇不存在，请重新选择!" ) withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10208]];//报修区域楼宇不存在
			
			[errorDic setObject:[self getError:NSLocalizedString(@"你筛选的状态为空，请重新选择!", @"你筛选的状态为空，请重新选择!") withOperate: OPERATION_OK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10209]];//筛选状态不能为空
			
//			[errorDic setObject:[self getError:NSLocalizedString(@"请求数据出错(报修单ID不能为空)，请重新请求!", @"请求数据出错，请重新请求!" ) withOperate: OPERATION_REQUEST_AGAIN]
//						 forKey:[NSNumber numberWithInt:ERROR_CODE_10210]];//报修单ID不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"您的报修信息不存在，请重新请求!", @"您的报修信息不存在，请重新请求!" ) withOperate: OPERATION_GO_BACK]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10211]];//报修信息不存在
			
			[errorDic setObject:[self getError:NSLocalizedString(@"请求数据出错，请重新请求!", @"请求数据出错，请重新请求!" ) 	withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10212]];//报修区域ID不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"请求数据出错，请重新请求!", @"请求数据出错，请重新请求!" ) withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10213]];//操作状态不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"请求数据出错，请重新请求!", @"请求数据出错，请重新请求!") withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_10214]];//操作状态不存在
			
			[errorDic setObject:[self getError:NSLocalizedString(@"请求超时,请重新请求!", @"请求超时,请重新请求!")withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_REQUEST_TIMEOUT]];//请求超时
			
			
			
			[errorDic setObject:[self getError:NSLocalizedString(@"应用不存在!", @"应用不存在!")withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_4016]];//appId错误, 应用不存在
			
			[errorDic setObject:[self getError:NSLocalizedString(@"appSecret不能为空!", @"appSecret不能为空!")withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_4017]];//appId, appSecret不能为空
			
			[errorDic setObject:[self getError:NSLocalizedString(@"应用密钥错误!", @"应用密钥错误!")withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_4031]];//应用密钥AppSecret错误
			
			[errorDic setObject:[self getError:NSLocalizedString(@"应用密钥错误!", @"应用密钥错误!")withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_4031]];//应用密钥AppSecret错误
			[errorDic setObject:[self getError:NSLocalizedString(@"口令牌校验失败!", @"口令牌校验失败!")withOperate: OPERATION_REQUEST_AGAIN]
						 forKey:[NSNumber numberWithInt:ERROR_CODE_4018]];//Token校验失败
			
        }
    }
    return self;
}

- (HOAPIError *)getError:(NSString *)content withOperate:(HO_ERROR_OPERATION)oper
{
	HOAPIError *err = [[[HOAPIError alloc] init] autorelease];
	err.errorMessage = content;
	err.operation = oper;
	return err;
}

- (void)unwrapContentWithErrorMessage:(NSString *)message
{
	NSArray *array = [message componentsSeparatedByString:@"_"];
	if([array count] == 2)
	{
		self.apiError.errorMessage = [array firstObject];
		self.apiError.operation = [[array lastObject] intValue];
	}
	self.apiError.errorMessage = message;
}

- (void)dealloc
{
    [self.dicData removeAllObjects];
    self.dicData = nil;
    
    [self.arrayData removeAllObjects];
    self.arrayData = nil;
    self.baseRequest = nil;
    self.jsonDic = nil;
    self.dataNode = nil;
    self.error = nil;
	self.apiError = nil;
    
    [super dealloc];
}
#pragma mark - -- handle responsed data

#pragma mark - -- verify data -- 

- (void)verifyResponseData:(id)data withWithServiceType:(HO_SERVICE_TYPE)serviceType
{
    if(data == nil)
    {
        self.apiError.errorCode = ERROR_CODE_RESPONSEDATA_EMPTY;
        return;
	}
    NSError *err = nil;
	NSString *content = [[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding];
	
	
	if(![self.action isEqualToString:kHO_ACTION_Login])
	{
		LogInf(@"data:************************\n%@\n*****************************", content);
	}
	[content release];
    id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers | NSJSONReadingMutableLeaves error:&err];
	self.apiError.errorCode = ERROR_CODE_NON;
    if (jsonObject != nil && self.error == nil)
    {
		if(![self.action isEqualToString:kHO_ACTION_Login])
		{
			LogInf(@"Successfully deserialized...:jsonObject%@", jsonObject);
		}
        if ([jsonObject isKindOfClass:[NSDictionary class]])
        {
            self.jsonDic = [NSMutableDictionary dictionaryWithDictionary:jsonObject];
			if(serviceType == HO_SERVICE_WEIDU)
			{
				[self parseWeiduData];
			}
			else
			{
				[self parseCaiyunData];
			}
        }
    }
    else if(jsonObject == nil)
    {
        self.apiError.errorCode = ERROR_CODE_RESPONSEDATA_EMPTY;
		LogErr(@"jsonObject == nil");
		NSString *content = NSLocalizedString(@"服务器返回数据格式出错!", @"服务器返回数据格式出错!");
        self.apiError.internalErrMessage = [NSString stringWithFormat:@"%@ action:%@", content, self.action];
		self.apiError.errorMessage = [NSString stringWithString:self.apiError.internalErrMessage];
		self.apiError.operation = OPERATION_REQUEST_AGAIN;
        return;
    }
    
    if(err != nil)
    {
        LogErr(@"An error happened while deserializing the JSON data. ERROR_CODE_JSONPARSE_FAILED");
        self.apiError.errorCode = ERROR_CODE_JSONPARSE_FAILED;
		self.apiError.internalErrMessage = NSLocalizedString(@"解析Json失败，请联系客服人员!", @"解析Json失败，请联系客服人员!");
		self.apiError.errorMessage = [NSString stringWithString:self.apiError.internalErrMessage];
		self.apiError.operation = OPERATION_REQUEST_AGAIN;
        return;
    }
}

- (void)parseWeiduData
{
	int code = [[self.jsonDic objectForKey:kHO_FIELD_CODE] intValue];
	if(code == 0)
	{
		self.dataNode = [self.jsonDic objectForKey:kHO_FIELD_DATA];
		
		self.apiError.errorCode = ERROR_CODE_NON;
		self.apiError.errorMessage = @"";
		self.apiError.internalErrMessage = @"";
		[self parseNodeData];
		return;
	}
	else
	{
		//code
		NSDictionary *headerDic = [self.jsonDic objectForKey:kHO_FIELD_HEADER];
		self.apiError.errorCode = code;
		self.apiError.internalErrMessage = [NSString stringWithString:[headerDic objectForKey:kHO_FIELD_ERRORMESSAGE]];
		HOAPIError *err = [errorDic objectForKey:[NSNumber numberWithInt:self.apiError.errorCode]];
		if(err != nil)
		{
			self.apiError = err;
		}
		self.apiError.errorCode = code;
		if(self.apiError.errorMessage == nil)
		{
			self.apiError.errorMessage = [headerDic objectForKey:kHO_FIELD_ERRORMESSAGE];
			return;
		}
		[self unwrapContentWithErrorMessage:self.apiError.errorMessage];
		return;
	}
}


#pragma mark - Caiyun data parse
- (void)parseCaiyunData
{
	
	/*
	 {
	 "status": 0,
	 "success": true,
	 "data": {
	 "accessToken":"MDAwMDkzMDQ3QkQzRkQ0QjcyMThDRjdGMjQw==",
	 "jsapiTicket":"MDAwMDkzMDQ3QkQzRkQ0QjcyMThDRjdGMjQw==",
	 "expireTime":1490602473644
	 }
	 }
	 
	 */
	int code = [[self.jsonDic objectForKey:kCY_FIELD_Status] intValue];
	if(code == 0)
	{
		self.dataNode = [self.jsonDic objectForKey:kHO_FIELD_DATA_Low];
		
		self.apiError.errorCode = ERROR_CODE_NON;
		self.apiError.errorMessage = @"";
		self.apiError.internalErrMessage = @"";
		[self parseNodeData];
		return;
	}
	else
	{
		/*
		 code(caiyun's status)
		 0	成功
		 4016	appId错误, 应用不存在
		 4017	appId, appSecret不能为空
		 4031	应用密钥AppSecret错误
		 */
		
		self.apiError.errorCode = code;
		HOAPIError *err = [errorDic objectForKey:[NSNumber numberWithInt:self.apiError.errorCode]];
		if(err != nil)
		{
			self.apiError = err;
			self.apiError.internalErrMessage = err.errorMessage;
			self.apiError.errorMessage = [self.jsonDic objectForKey:kCY_FIELD_Message];
		}
		return;
	}
}


- (void)parseNodeData
{
    if(self.apiError.errorCode != ERROR_CODE_NON || self.jsonDic == nil)
    {
        LogInf(@"Invalide reqeust data :%@", self.apiError.errorMessage);
        return;
    }
	
//    LogInf(@"Successfully data node deserialized...");
    if ([self.dataNode isKindOfClass:[NSDictionary class]])
    {
        NSDictionary *deserializedDic = (NSDictionary *)self.dataNode;
//        LogInf(@"deserializedDic:%@", deserializedDic);
        [self parseDicData:deserializedDic];
    }
    else if ([self.dataNode isKindOfClass:[NSArray class]])
    {
        NSArray *deserializedArray = (NSArray *)self.dataNode;
//        LogInf(@"deserializedArray:%@", deserializedArray);
        [self parseArrayData:deserializedArray];
    }
    else if ([self.dataNode isKindOfClass:[NSArray class]])
    {
        NSArray *deserializedArray = (NSArray *)self.dataNode;
        //        LogInf(@"deserializedArray:%@", deserializedArray);
        [self parseArrayData:deserializedArray];
    }
    else if ([self.dataNode isKindOfClass:[NSString class]])
    {
        self.strData = (NSString *)self.dataNode;
        //        LogInf(@"deserializedArray:%@", deserializedArray);
        [self parseStringData:self.strData];
    }
    else
    {
        
        LogInf(@"An error happened while deserializing the JSON data.ERROR_CODE_JSON_DATANODE_INVALIDE");
//        errorCode = ERROR_CODE_JSON_DATANODE_INVALIDE;
    }
}

- (void)parseArrayData:(NSArray *)arrayData
{
//    LogInf(@"AMBaseResponseEntity parseArrayData:%@", arrayData);
}
- (void)parseDicData:(NSDictionary *)dicData
{
//    LogInf(@"AMBaseResponseEntity parseDicData:%@", dicData);
}
- (void)parseStringData:(NSString *)stringData
{
        LogInf(@"AMBaseResponseEntity stringData:%@", stringData);
}

- (HO_ERROR_OPERATION)getOperation
{
	return self.apiError.operation;
}

- (NSString *)getErrorMessage
{
	return self.apiError.errorMessage;
}

- (void)setErrorMessage:(NSString *)content
{
	self.apiError.errorMessage = content;
}

- (NSString *)getInternalErrorMessage
{
	return self.apiError.internalErrMessage;
}

- (void)setInternalMessage:(NSString *)content
{
	self.apiError.internalErrMessage = content;
}

- (AM_ERROR_CODE)getErrorCode
{
	return self.apiError.errorCode;
}

- (BOOL)isValidatedArray:(NSArray *)array
{
	if(array == nil)
		return NO;
	if(![array isKindOfClass:[NSArray class]])
		return NO;
	return YES;
}

- (void)setErrorCode:(AM_ERROR_CODE)errCode
{
	HOAPIError *err = [errorDic objectForKey:[NSNumber numberWithInt:errCode]];
	self.apiError = err;
	self.apiError.errorCode = errCode;
}

- (HO_REQUEST_STATUS)getStatus
{
	if(!self.baseRequest)
	{
		return HO_REQUEST_STATUS_FAILED;
	}
	return self.baseRequest.status;
}

- (BOOL)isRequestDone
{
	return [self getStatus] == HO_REQUEST_STATUS_DONE;
}
- (BOOL)isEqualAction:(NSString *)action
{
	return [self.action isEqualToString:action];
}

- (NSString *)description
{
    return [NSString stringWithFormat:@"AMBaseResponseEntity - action:%@ pointer:%@", self.action, [super description]];
}

@end
